<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import {Data,mvRootObject} from '@/types/userMv.uts'
import {getMvUrlAPI,} from '@/apis/music.uts'
// MV数据
const mvInfo = ref<any[] | Data>([]) as any;
const url = ref<any>('');
// 相关推荐数据
const relatedList = ref<any[]>([]);
const id = ref<string>('');
// 格式化播放量
const formatCount = (num) => {
  return num > 10000 ? `${(num/10000).toFixed(1)}万` : num;
};

// 播放推荐MV
const playRecommended = (item):any => {
  mvInfo.value = {
    ...item,
    videoUrl: '/static/mock/mv-sample.mp4',
    playCount: Math.floor(Math.random()*10000000),
    publishTime: '2023-08-20',
    description: '推荐MV的演示描述文本...'
  };
  uni.pageScrollTo({ scrollTop: 0, duration: 300 });
};
onLoad(async (options) => {
  // 获取MV数据
  
   const id= options.id
  const res = await getMvUrlAPI(id) as mvRootObject;
  mvInfo.value = res?.data;
  // 获取MV播放地址
  url.value = res?.data.url;
   console.log(res);
  // 获取相关推荐数据
  
});

</script>

<template>
 <scroll-view class="mv-container" direction='vertical' :show-scrollbar='false' >
 	 <view >
		  <view class="container">
 	    <!-- 视频播放区域 -->
 	    <video 
 	      class="video-player"
 	      :src="url"
 	      :controls='true'
 	      autoplay
		  :direction='-90'
 	      objectFit="cover"
 	      show-fullscreen-btn
		  object-fit="cover"
 	      show-play-btn
		  :page-gesture='true'
 	    >
 	    </video>
		</view>
 	    <!-- MV信息区域 -->
 	    <view class="mv-info">
 	      <view class="meta-section">
 	        <text class="artist">{{ mvInfo.artist }}</text>
 	        <text class="album">{{ mvInfo.album }}</text>
 	      </view>
 	      
 	    </view>
 	
 	    <!-- 相关推荐 -->
 	    <view class="related-section">
 	      <text class="section-title">相关推荐</text>
 	      <scroll-view class="related-list"  direction='vertical' :show-scrollbar='false'>
 	        <view 
 	          v-for="item in relatedList" 
 	          :key="item.id"
 	          class="related-item"
 	          @click="playRecommended(item)"
 	        >
 	          <image class="related-cover" :src="item.cover" mode="aspectFill" />
 	          <text class="related-title">{{ item.title }}</text>
 	          <text class="related-artist">{{ item.artist }}</text>
 	        </view>
 	      </scroll-view>
 	    </view>
 	  </view>
 </scroll-view>
</template>



<style lang="scss">
	
.mv-container {
  background-color: #fff;
 height: 100%;

  .nav-bar {
    position: fixed;
    top: 0;
    width: 100%;
    height: 88rpx;
    background: #fff;
    z-index: 100;
    display: flex;
    align-items: center;
    padding: 0 32rpx;
    box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.05);

    .back-btn {
      color: #e94b40;
      font-size: 30rpx;
      margin-right: 40rpx;
    }

    .mv-title {
      font-size: 34rpx;
      font-weight: bold;
      color: #333;
    }
  }

  .video-player {
    width: 100%;
    height: 422rpx;
    margin-top: 88rpx;
    background: #000;

    .video-cover {
      width: 100%;
      height: 100%;
    }
  }

  .mv-info {
    padding: 32rpx;

    .meta-section {
		
      margin-bottom: 24rpx;

      .artist {
        font-size: 36rpx;
        color: #333;
        margin-right: 24rpx;
      }

      .album {
        font-size: 28rpx;
        color: #666;
      }
    }

    .stats-section {
      display: flex;
      margin-bottom: 32rpx;

      .play-count {
        font-size: 26rpx;
        color: #888;
        margin-right: 40rpx;
      }

      .publish-time {
        font-size: 26rpx;
        color: #888;
      }
    }

    .description {
      font-size: 28rpx;
      color: #666;
      line-height: 1.6;
    }
  }

  .related-section {
	  display: flex;
	  flex-direction: column;
	 
	  justify-content: space-evenly;
    padding: 0 32rpx;

    .section-title {
    
      font-size: 32rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 32rpx;
    }

    .related-list {
      white-space: nowrap;
 margin: 0 auto;
	  
      .related-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 280rpx;
        margin-right: 24rpx;

        .related-cover {
          width: 100%;
          height: 160rpx;
          border-radius: 12rpx;
          margin-bottom: 16rpx;
        }

        .related-title {
          display: block;
          font-size: 28rpx;
          color: #333;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .related-artist {
          font-size: 24rpx;
          color: #888;
        }
      }
    }
  }
}
</style>